from flask import Flask, views

app = Flask(__name__)
app.debug = True


class RouteDecorator:
    def __init__(self, url_rule, cls_name=None, **kwargs):
        self.url_rule = url_rule
        self.kwargs = kwargs
        self.cls_name = cls_name

    def __call__(self, cls):
        if self.kwargs.get('view_func'):
            del self.kwargs['view_func']

        if self.cls_name is None:
            view_func = cls.as_view(cls.__name__)
        else:
            view_func = cls.as_view(self.cls_name)
        app.add_url_rule(self.url_rule, view_func=view_func, **self.kwargs)
        return cls


@RouteDecorator('/index')
class IndexView(views.MethodView):

    def get(self):
        return 'index get'

    def post(self):
        return 'index post'


if __name__ == '__main__':
    app.run()
